package logic

import (
	"center-data-platform/app/user/api/model"
	"center-data-platform/app/user/rpc/internal/svc"
	"center-data-platform/app/user/rpc/user"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
	return &InfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *InfoLogic) Info(in *user.UserInfoReq) (*user.UserInfoResp, error) {
	//res, err := l.svcCtx.UserModel.FindOne(l.ctx, in.Id)
	var res model.User
	err := l.svcCtx.DB.First(&res, in.Id).Error
	if err != nil {
		return nil, err
	}
	return &user.UserInfoResp{
		Id:          res.Id,
		UserName:    res.UserName,
		Email:       res.Email,
		Phone:       res.Phone,
		Avatar:      res.Avatar.String,
		Bio:         res.Bio.String,
		Status:      res.Status,
		Role:        res.Role,
		CreatedTime: res.CreatedTime.Format("2006-01-02 15:04:05"),
	}, nil
}
